﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HAC
{
    public class ClusterPair
    {
        Cluster cluster1;
        Cluster cluster2;
        float distance;

        public Cluster Cluster1
        {
            get { return cluster1; }
        }

        public Cluster Cluster2
        {
            get { return cluster2; }
        }

        public float Distance
        {
            get { return distance; }
        }

        public void update(Cluster oldCluster, Cluster newCluster)
        {
            if (cluster1.id == oldCluster.id)
            {
                this.cluster1 = newCluster;
            }
            else
            {
                this.cluster2 = newCluster;
            }
            this.distance = cluster1.CalculateDistance(cluster2);
            HAC.updateRelatedClustersOfOneCluster(cluster1.id, cluster2.id);
            HAC.updateRelatedClustersOfOneCluster(cluster2.id, cluster1.id);
        }

        public ClusterPair(Cluster cluster1, Cluster cluster2, float distance)
        {
            this.cluster1 = cluster1;
            this.cluster2 = cluster2;
            this.distance = distance;            
        }

        internal int HasCluster(Cluster cluster)
        {
            if (cluster1 == cluster)
            {
                return 1;
            }
            else if (cluster2 == cluster)
            {
                return 2;
            }
            else
            {
                return 0;
            }
            //return cluster1 == cluster || cluster2 == cluster;
        }

    }
}
